<!DOCTYPE html>
<html>
<head>
<title>文章管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<#include "../../../include/resources.html">
<script type="text/javascript">
	var treeGrid;
	var winWidth =  800;
	var winHeight = 460;
	var addTitle = "添加栏目";
	var addUrl =  "/modules/column/site/siteAddPage.html";
	var editTitle = "编辑栏目";
	var editUrl =  "/modules/column/site/siteEditPage.html";
	var deleteUrl = "/modules/column/site/siteDelete.html";	//删除记录接口地址
	var cleanUrl = "/modules/system/sconfig/clean.html";//清理缓存
	var siteMapUrl = "/modules/siteMap/siteMapConfig/siteMapAdd.html";//生成siteMap
	
	var deleteWinParmeters = "'{0}','"+deleteUrl+"'";
	$(function() {
		var editIndex = undefined;
		treeGrid = $('#treeGrid').treegrid({
			url : 'siteList.html',
			fit : true,
			fitColumns : true,
			checkbox:true,
			border : false,
            		loadFilter: function(rows){return $.convert(rows.rows); },
			idField : 'id',
			treeField : 'name',
			sortOrder : 'asc',
			pagination:false,
			checkOnSelect : false,
			selectOnCheck : false,
			nowrap : false,
			singleSelect:true,
			frozenColumns:[[
				{ field: 'name', title: '名称', width: 180, sortable : false},
				{ field: 'nid', title: '标识', width: 80, sortable : false},
				{ field: 'status', title: '状态', width: 50, sortable:false,
					formatter:function(value, row, index){
						if(value == 0){
							return "隐藏";
						}else if(value == 1){
							return "显示";
						}
						return "";
					}	
				},
			]],
			columns : [ [ 			
			{ field: 'type', title: '类型', width: 100, sortable:false,
				formatter:function(value, row, index){
					if(value == 1){
						return "列表";
					}else if(value == 2){
						return "单页";
					}else if(value == 3){
						return "站内链接";
					}else if(value == 4){
						return "站外链接";
					}
					return "";
				}	
			},
 			{ field: 'url', title: '跳转链接', width: 250, sortable:false },
 			{ field: 'description', title: '描述', width: 200, sortable:false },
			{ field: 'keyWord', title: '关键字', width: 200, sortable:false },
			{ field: 'seoTitle', title: 'SEO标题', width: 200, sortable:false },
 			{ field: 'sort', title: '排序', width: 50, sortable:false },
 			{ field: 'size', title: '显示个数', width: 100, sortable:false },
			{ field: 'addTime', title: '添加时间', width: 150,
				formatter: function(value,row,index){
					if (value){
						return getLocalTime(value,4);
					} else {
						return "";
					}
				}
			},
			{field:'addIp', title:'添加IP',width: 100},
			{	field : 'action',
				title : '操作',
				width :75,
				fixed:true,
				align:'center',
				formatter : function(value, row, index) {
					var str = '';
					str += '<dl>';
					str += '<dt><a href="javascript:void(0);">详情</a><i class="iconfont">&#xe639;</i></dt>' ;
					str += '<dd>';
					if (row.level!=3) {
						str += '<a href="javascript:void(0);" onclick="$.fn.treeGridOptions.addFun('+row.id+',addTitle,winWidth,winHeight,addUrl);" title="'+addTitle+'">添加</a>';
					}
					str += '<a href="javascript:void(0);" onclick="$.fn.treeGridOptions.editFun('+row.id+',editTitle,winWidth,winHeight,editUrl);" title="'+editTitle+'">编辑</a>';
					str += '</dd>'
					str +=  '</dl>'
					return str;
				}
			} ] ],
			toolbar : '#toolbar',
			onLoadSuccess : function() {
				$('#searchForm table').show();
				parent.$.messager.progress('close');
			},
			onRowContextMenu : function(e, rowIndex, rowData) {
				e.preventDefault();
				$(this).treegrid('unselectAll').treegrid('uncheckAll');
				$(this).treegrid('selectRow', rowIndex);
				$('#menu').menu('show', {
					left : e.pageX,
					top : e.pageY
				});
			}
		});
	});
	
	
	//平滑数据格式转换
	$.convert = function (rows){
	    if(!rows) return;
		function exists(rows, parentId){
			for(var i=0; i<rows.length; i++){
				if (rows[i].id == parentId) return true;
			}
			return false;
		}		
		var nodes = [];
		// 获取顶级菜单
		for(var i=0; i<rows.length; i++){
			var row = rows[i];
			if (!exists(rows, row.pid)){
				nodes.push({id:row.id,name:row.name,nid:row.nid,pid:row.pid,status:row.status,type:row.type,url:row.url,description:row.description,sort:row.sort,size:row.size,addTime:row.addTime,addIp:row.addIp,level:row.level,keyWord:row.keyWord,seoTitle:row.seoTitle});
			}
		}		
		var toDo = [];
		for(var i=0; i<nodes.length; i++){
			toDo.push(nodes[i]);
		}
		while(toDo.length){
			var node = toDo.shift();	// 父级节点
			// 获取子级节点
			for(var i=0; i<rows.length; i++){
				var row = rows[i];
				if (row.pid == node.id){
					var child = {id:row.id,name:row.name,nid:row.nid,pid:row.pid,status:row.status,type:row.type,url:row.url,description:row.description,sort:row.sort,size:row.size,addTime:row.addTime,addIp:row.addIp,level:row.level,keyWord:row.keyWord,seoTitle:row.seoTitle};
					if (node.children){
						node.children.push(child);
					} else {
						node.children = [child];
					}					
					toDo.push(child);
				}
			}
		}
		return nodes;
	}
	
</script>
</head>
<body style="padding:0 20px;" >
	<div class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',border:false,collapsible:false" id="searchBox">
            <div class="sRight">
				<a onclick="$.fn.treeGridOptions.addFun(-1,addTitle,winWidth,winHeight,addUrl);" href="javascript:void(0);" class="addBtn"><i class="iconfont">&#xe629;</i>添加</a>
				<a onclick="$.fn.formOptions.btnSubFun(clean_cache,cleanUrl,'','')" href="javascript:void(0);" class="addBtn"><i class="iconfont">&#xe603;</i>清理缓存</a>
				<a onclick="$.fn.formOptions.btnSubFun(clean_cache,siteMapUrl,'','')" href="javascript:void(0);" class="addBtn"><i class="iconfont">&#xe603;</i>生成siteMap</a>
            </div>
         </div>
		<div data-options="region:'center'" style="margin-top:30px;padding-bottom:30px;">
			<table id="treeGrid"></table>
		</div>
	</div>
	<!-- 清理缓存 -->
	<form id="clean_cache"></form>
</body>
</html>
